<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      class="globalSerchFormStyle"
      label-width="90px"
    >
      <el-row>
        <el-col :span="6">
          <el-form-item label="积分订单号" prop="integralOrderNo">
            <el-input
              v-model="queryParams.integralOrderNo"
              placeholder="请输入积分订单号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
              style="width: 180px"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="商品名称" prop="waresName">
            <el-input
              v-model="queryParams.waresName"
              placeholder="请输入商品名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
              style="width: 180px"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="会员名称" prop="customerName">
            <el-input
              v-model="queryParams.customerName"
              placeholder="请输入会员名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
              style="width: 180px"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="兑换时间" prop="exchangeTimeRange">
            <el-date-picker
              clearable
              size="small"
              style="width: 190px"
              v-model="exchangeTimeRange"
              type="datetimerange"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择兑换时间"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="手机号" prop="mobilePhone">
            <el-input
              v-model="queryParams.mobilePhone"
              placeholder="请输入手机号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
              style="width: 180px"
              type="text"
              maxlength="11"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-row class="global_el_rowStyle" :gutter="10">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-col>
    </el-row>

    <el-table :data="orderList" stripe v-loading="tableLoading">
      <af-table-column label="序号" align="left" type="index" width="50px" />
      <af-table-column label="订单号" align="left" prop="integralOrderNo" />
      <af-table-column label="会员名称" align="left" prop="customerName" />
      <af-table-column label="手机号" align="left" prop="mobilePhone" />
      <af-table-column label="商品名称" align="left" prop="waresName" />
      <af-table-column label="兑换消耗积分" align="left" prop="integral" />
      <af-table-column label="兑换数量" align="left" prop="exchangeNum" />
      <af-table-column
        label="兑换时间"
        align="left"
        prop="exchangeTime"
        width="180"
      />
      <af-table-column label="核销状态" align="left" prop="writeOffStatus">
        <template slot-scope="scope">
          <span>
            {{ scope.row.writeOffStatus === 1 ? "已核销" : "未核销" }}
          </span>
        </template>
      </af-table-column>
      <af-table-column label="兑换数量" align="left" prop="exchangeNum" />
      <af-table-column label="核销时间" align="left" prop="writeOffTime" />
      <!-- <af-table-column label="积分订单id" align="left" prop="id" v-if="false" /> -->
      <!--
      <af-table-column
        label="订单状态"
        align="left"
        prop="status"
        :formatter="statusFormat"
      />
      -->
      <!-- <af-table-column
          label="商品类型"
          align="left"
          prop="waresType"
          v-if="false"
        /> -->
      <!-- 
        <af-table-column
          label="微信唯一标识"
          align="left"
          prop="unionId"
          v-if="false"
        /> -->

      <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.exchangeTime, "{y}-{m}-{d}") }}</span>
        </template> -->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listOrder,
  getOrder,
  delOrder,
  addOrder,
  updateOrder,
  exportOrder,
} from "@/api/integral/order";

export default {
  name: "Order",
  data() {
    return {
      // 总条数
      total: 0,
      // 积分消费订单表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        integralOrderNo: null,
        waresType: null,
        waresName: null,
        unionId: null,
        customerName: null,
        exchangeNum: null,
        exchangeTime: null,
        status: null,
        levelId: this.levelId,
        mobilePhone: null,
      },
      exchangeTimeRange: [],
      // 表单参数
      form: {},
      tableLoading: false,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    statusFormat(row, column) {
      if (row.status === "1") {
        return "已兑换";
      } else if (row.status === "2") {
        return "兑换中";
      }
    },
    /** 查询积分消费订单列表 */
    getList() {
      this.tableLoading = true;
      // this.queryParams.stationId = this.deptId;
      this.queryParams.levelId = this.levelId;
      console.log("5555", this.exchangeTimeRange);
      if (this.exchangeTimeRange && this.exchangeTimeRange.length) {
        this.queryParams.beginTime = this.exchangeTimeRange[0];
        this.queryParams.endTime = this.exchangeTimeRange[1];
      } else {
        this.queryParams.beginTime = "";
        this.queryParams.endTime = "";
      }
      listOrder(this.queryParams).then((response) => {
        this.tableLoading = false;
        this.orderList = response.rows;
        this.total = response.total;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        integralOrderNo: null,
        waresType: null,
        waresName: null,
        unionId: null,
        customerName: null,
        exchangeNum: null,
        exchangeTime: null,
        status: "0",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.exchangeTimeRange = [];
      this.handleQuery();
    },
  },
};
</script>
